package com.myacg.editor.common.unit.panel.taskpanel;

import java.awt.BorderLayout;

import javax.swing.JPanel;

import com.myacg.editor.common.entity.CoupleDao;
import com.myacg.editor.common.unit.list.FlowListPanel;
import com.myacg.editor.common.unit.list.ListEvent;
import com.myacg.editor.common.unit.list.item.CoupleDataListItem;
import com.myacg.editor.common.unit.list.item.FlowListItem;

public class KeeptaskInfoPanel extends JPanel{
	private UIKeepTask  uiKeepTask;
	private FlowListPanel<CoupleDao> listPanel;
	private CoupleDao  infoId,infoName,infoCount,infoSecond,infoNow ;
	public KeeptaskInfoPanel(){
		listPanel = new FlowListPanel<>(CoupleDataListItem.class);
		this.setLayout(new BorderLayout());
		infoId = new CoupleDao("任务ID : ", "");
		infoName = new CoupleDao("任务名称 : ", "");
		infoSecond = new CoupleDao("任务执行间隔 : ","");
		infoCount = new CoupleDao("任务执行次数 : ", "");
		infoNow  = new CoupleDao("计算时间 : ", "");
		listPanel.addItem(infoId);
		listPanel.addItem(infoName);
		listPanel.addItem(infoSecond);
		listPanel.addItem(infoCount);
		listPanel.addItem(infoNow);
		this.add(listPanel,BorderLayout.CENTER);
	}
	
	public void updateData(){
		if(uiKeepTask != null){
			infoId.setValue( uiKeepTask.getId());
			infoName.setValue(uiKeepTask.getTaskName());
			infoSecond.setValue( uiKeepTask.getHowSecond()+"毫秒");
			infoCount.setValue(uiKeepTask.getExecuteCount()+"次");
			infoNow.setValue(uiKeepTask.getInitSecond()+"毫秒");
		}else{
			infoId.setValue("");
			infoName.setValue("");
			infoSecond.setValue("");
			infoCount.setValue("");
			infoNow.setValue("");
		}
		for (String id : listPanel.getItemList().keySet()) {
			listPanel.getItemList().get(id).repaint();
		}
	}

	public UIKeepTask getUiKeepTask() {
		return uiKeepTask;
	}

	public void setUiKeepTask(UIKeepTask uiKeepTask) {
		this.uiKeepTask = uiKeepTask;
		this.updateData();
	}
	
}
